#include <cstdint>

using namespace std;

class Solution {
private:
    double binary_pow(double x, int64_t n) {
        if (n == 0) {
            return 1;
        } else if (n == 1) {
            return x;
        }
        double ans = binary_pow(x, n / 2);
        if (n % 2 == 0) {
            return ans * ans;
        } else {
            return ans * ans * x;
        }
    }
public:
    double myPow(double x, int n) {
        int64_t fix_n = n;
        if (fix_n < 0) {
            fix_n = -fix_n;
            x = 1 / x;
        }
        return binary_pow(x, fix_n);
    }
};